

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */

//elixir(function(mix) {
//    mix.sass('app.scss');
//});

// 引入 gulp及组件
var gulp    = require('gulp'),                 //基础库
    imagemin = require('gulp-imagemin'),       //图片压缩
    sass = require('gulp-ruby-sass'),          //sass
    minifycss = require('gulp-minify-css'),    //css压缩
    jshint = require('gulp-jshint'),           //js检查
    uglify  = require('gulp-uglify'),          //js压缩
    rename = require('gulp-rename'),           //重命名
    concat  = require('gulp-concat'),          //合并文件
    clean = require('gulp-clean'),             //清空文件夹
    tinylr = require('tiny-lr'),               //livereload
    server = tinylr(),
    port = 35729,
    livereload = require('gulp-livereload');  //livereload



var compareSource = [
    {source:'./resources/assets/scripts/admin/**/*.js',target:'./public/build/r001/js',name:"admain.js"},

];



gulp.task('js', function () {
    for(var i=0; i<compareSource.length;i++){
        var item = compareSource[i];
        console.log(item.name+ ":开始打包")
        gulp.src(item.source)
            //.pipe(ngAnnotate())
            //.pipe(jshint('.jshintrc'))
            .pipe(jshint.reporter('default'))
            .pipe(concat(item.name))
            .pipe(gulp.dest(item.target))
            .pipe(rename({ suffix: '.min' }))
            .pipe(uglify())
            .pipe(livereload(server))
            .pipe(gulp.dest(item.target));

        console.log(item.name+ ":打包结束")
    }
});


// 监听任务 运行语句 gulp watch
gulp.task('watch',function(){

    server.listen(port, function(err){
        if (err) {
            return console.log(err);
        }

        for(var i=0; i<compareSource.length;i++) {
            var item = compareSource[i];
            gulp.watch(item.source, function(){
                gulp.run('js');
            });
        }

    });
});